package statistics;

import java.util.Random;


public class GeometricDistribution extends Distribution{

    protected double p;
    protected int n;
    
    public GeometricDistribution( double p , Random random ){
        this.p = p;
        this.random = random;
 
    }
            

    public double expectation() {
       return 1/p;
    }


    public double variance() {
        return (1-p) / (p*p);
    }


    public double nextRandom() {
        double U;
        int counter=0;
        boolean success = false;
        while(!success){
            U = random.nextDouble();
            counter++;
            if(U<=p) {
                success = true;
            }
            
        }
        
        return counter;
        
    }
    
    
}